package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.dto.InformationDTO;
import com.example.domain.Information;
import com.example.service.InformationService;
import com.example.mapper.InformationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 惠普
 * @description 针对表【information】的数据库操作Service实现
 * @createDate 2022-09-27 15:05:30
 */
@Service
public class InformationServiceImpl extends ServiceImpl<InformationMapper, Information>
		implements InformationService {

	@Override
	public Page<Information> getInfoByConditionPage(InformationDTO dto) {
		Page<Information> page = new Page<>(dto.getCurrentPage(), dto.getPageSize());
		QueryWrapper<Information> query = new QueryWrapper<>();
		query.eq(ObjectUtils.isNotNull(dto.getUserId()), "user_id", dto.getUserId())
				.eq(ObjectUtils.isNotNull(dto.getCommodityId()), "commodity_id", dto.getCommodityId())
				.like(ObjectUtils.isNotNull(dto.getAppraiseInformation()), "appraise_information", dto.getAppraiseInformation());
		return baseMapper.selectPage(page, query);
	}

	@Override
	public List<Information> getInfoByCondition(InformationDTO dto) {
		QueryWrapper<Information> query = new QueryWrapper<>();
		query.eq(ObjectUtils.isNotNull(dto.getUserId()), "user_id", dto.getUserId())
				.eq(ObjectUtils.isNotNull(dto.getCommodityId()), "commodity_id", dto.getCommodityId())
				.like(ObjectUtils.isNotNull(dto.getAppraiseInformation()), "appraise_information", dto.getAppraiseInformation());
		return baseMapper.selectList(query);
	}
}




